﻿using LxBasic;
using LxCore;

namespace LxCore
{
    public abstract class ConstField
    {
        public abstract class Base<T> : ParameterBase<T>, IFaceVarArr<T>, ICellVarArr<T>
        {
            public Base() { }
            public Base(T number)
            {
                this.Number = number;
            }
            private T _Number;
            public T Number
            {
                get { return _Number; }
                set { _Number = value; }
            }
            public override T GetPara()
            {
                return _Number;
            }
            public T GetCellVar(int cellIndex) => _Number;
            public T GetFaceVar(int faceIndex) => _Number;
            public override ICellVarArr<T> GetCellVarArr(IIndexHost indexHost) => this;
            public override IFaceVarArr<T> GetFaceVarArr(IIndexHost indexHost) => this;
            public override string ToString()
            {
                return _Number.ToString();
            }
        }
        public class Double : Base<double>
        {
            public Double() { }
            public Double(double number) : base(number) { }
            public override void FromJsonKV(string key, IJsonReader jsReader)
            {
                switch (key)
                {
                    case nameof(Number): Number = jsReader.ReadDouble(); break;
                    default: base.FromJsonKV(key, jsReader); break;
                }
            }
            public override void ToJsonKV(IJsonWriter writer)
            {
                writer.WriteDouble(nameof(Number), Number);
            }
        }
        public class Vector : Base<Vector3d>
        {
            public Vector() { }
            public Vector(Vector3d number) : base(number) { }
            public override void FromJsonKV(string key, IJsonReader jsReader)
            {
                switch (key)
                {
                    case nameof(Number): Number = jsReader.ReadVector3d(); break;
                    default: base.FromJsonKV(key, jsReader); break;
                }
            }
            public override void ToJsonKV(IJsonWriter writer)
            {

                writer.WriteVector3d(nameof(Number), Number);
            }
        }
        public static readonly Double Double0 = new Double(0);
        public static readonly Double Double1 = new Double(1);
        public static readonly Vector Vector0 = new Vector(new Vector3d(0, 0, 0));
    }
}
//public override bool IsEqual0()
//{
//    return Number.IsEqual0();
//}
//public override bool IsEqual0()
//{
//    return Number == 0;
//}